/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Haystack Software Inc. All rights reserved.
 *  Licensed under the PolyForm Strict License 1.0.0. See License.txt in the project root for
 *  license information.
 *--------------------------------------------------------------------------------------------*/

/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See code-license.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { IEditorOptions } from "vs/editor/common/config/editorOptions"
import { TextModel } from "vs/editor/common/model/textModel"
import { ViewModel } from "vs/editor/common/viewModel/viewModelImpl"
import { TestConfiguration } from "vs/editor/test/browser/config/testConfiguration"
import { MonospaceLineBreaksComputerFactory } from "vs/editor/common/viewModel/monospaceLineBreaksComputer"
import { createTextModel } from "vs/editor/test/common/testTextModel"
import { TestLanguageConfigurationService } from "vs/editor/test/common/modes/testLanguageConfigurationService"
import { TestThemeService } from "vs/platform/theme/test/common/testThemeService"

export function testViewModel(
  text: string[],
  options: IEditorOptions,
  callback: (viewModel: ViewModel, model: TextModel) => void
): void {
  const EDITOR_ID = 1

  const configuration = new TestConfiguration(options)
  const model = createTextModel(text.join("\n"))
  const monospaceLineBreaksComputerFactory =
    MonospaceLineBreaksComputerFactory.create(configuration.options)
  const testLanguageConfigurationService =
    new TestLanguageConfigurationService()
  const viewModel = new ViewModel(
    EDITOR_ID,
    configuration,
    model,
    undefined,
    undefined,
    monospaceLineBreaksComputerFactory,
    monospaceLineBreaksComputerFactory,
    null!,
    testLanguageConfigurationService,
    new TestThemeService(),
    {
      setVisibleLines(visibleLines, stabilized) {},
    }
  )

  callback(viewModel, model)

  viewModel.dispose()
  model.dispose()
  configuration.dispose()
  testLanguageConfigurationService.dispose()
}
